jQuery(function() {
	if (jQuery("#deliveryDate1").val() != "") {
		jQuery("#deliveryDate").val(
				moment(jQuery("#deliveryDate1").val()).format("YYYY-MM-DD"));
	}
	if (jQuery("#sendDateThree1").val() != "") {
		jQuery("#sendDateThree").val(
				moment(jQuery("#sendDateThree1").val()).format("YYYY-MM-DD"));
	}
	if (jQuery("#dealDate1").val() != "") {
		jQuery("#dealDate").val(
				moment(jQuery("#dealDate1").val()).format("YYYY-MM-DD"));
	}
	var dutyBlongThree = jQuery("#dutyBlongThree1").val();
	var outsourcing = jQuery("#outsourcing1").val();
	var selfMake = jQuery("#selfMake1").val();
	$(":radio[name='dutyBlongThree'][value='" + dutyBlongThree + "']").prop(
			"checked", "checked");
	$(":radio[name='outsourcing'][value='" + outsourcing + "']").prop(
			"checked", "checked");
	$(":radio[name='selfMake'][value='" + selfMake + "']").prop("checked",
			"checked");
	// /////////////////////附件上传下载///////////////////////////
	// 传真，邮件
	jQuery(".upMail").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"传真邮件",null,'mailNum');
	});
	jQuery(".downMail").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'传真邮件',1);
	});
    showANum(jQuery("#ticketId").val(),'传真邮件',"mailNum");
	
   
	// 质量反馈表
    jQuery(".upQuality").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"质量反馈表",null,'qualityNum');
	});
	jQuery(".downQuality").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'质量反馈表',1);
	});
    showANum(jQuery("#ticketId").val(),'质量反馈表',"qualityNum");
	// 技术方案
    jQuery(".upPlan").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"技术方案",null,'planNum');
	});
	jQuery(".downPlan").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'技术方案',1);
	});
	showANum(jQuery("#ticketId").val(),'技术方案',"planNum");
	// 返厂泵处理表
	jQuery(".upDealForm").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"返厂泵处理表",null,'dealFormNum');
	});
	jQuery(".downDealForm").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'返厂泵处理表',1);
	});
	showANum(jQuery("#ticketId").val(),'返厂泵处理表',"dealFormNum");
	// 其它
	jQuery(".upOther").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"其它",null,'otherNum');
	});
	jQuery(".downOther").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'其它',1);
	});
	showANum(jQuery("#ticketId").val(),'其它',"otherNum");
	
	
	// 三包办理明细
	jQuery(".upDetail").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"三包办理明细",null,"detailNum");
	});
	jQuery(".downDetail").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'三包办理明细',1);
	});
	showANum(jQuery("#ticketId").val(),'三包办理明细',"detailNum");
	// 执行过程
	jQuery(".upProcess").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"执行过程",null,"processNum");
	});
	jQuery(".downProcess").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'执行过程',1);
	});
	showANum(jQuery("#ticketId").val(),'执行过程',"processNum");
	// 三包图片
	jQuery(".upPicture").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"三包图片",null,'pictureNum');
	});
	jQuery(".downPicture").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'三包图片',1);
	});
	showANum(jQuery("#ticketId").val(),'三包图片',"pictureNum");
	// 返厂维修意见
	jQuery(".backAdviceUp").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
		fileUpload(ticketId,"返厂维修意见",null,"backAdviceNum");
	});
	jQuery(".backAdviceDown").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'返厂维修意见',1);
	});
	showANum(jQuery("#ticketId").val(),'返厂维修意见',"backAdviceNum");
   ///下载回执单
	jQuery(".downRecipt").on('click',function(){
		var ticketId=jQuery("#ticketId").val();
    	filedown(ticketId,'售后回执单',0);
	});
	showANum(jQuery("#ticketId").val(),'售后回执单',"receiptNum");
	
////////上传下载结束////////
	if (jQuery("#isMatch1").val() == "0") {
		jQuery("#isMatch").val("否");
	} else {
		jQuery("#isMatch").val("是");
	}

	if (jQuery("#isArrive1").val() == "0") {
		jQuery("#isArrive").val("否");
	} else
		jQuery("#isArrive").val("是");
	var ticketId = $("#ticketId").val();
	var serverData = {};
	serverData.ticketId = ticketId;
	var serverTable;
	jQuery(document).ready(function() {
				serverTable = jQuery('#ticketTable').DataTable({
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/afterSaleOutHouse/getTrancePersonPage',
												"data" : function(d) {
													return $.extend({}, d,
															serverData);
												}
											},
											"iDisplayLength" : 5,
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
														data: null,
									                	 render: function (data, type, full, meta) {
										                        var dOut;
										                        if(data.outState=="0"){
										                            dOut = '<td class="center" ><span class="badge label-pill label-danger">未接收</span></td>';
										                        }     
										                        else if(data.outState=="1") {
										                            dOut = '<td class="center" ><span class="badge label-pill label-primary">已接收</span></td>';
										                        }   
										                        else if(data.outState=="2") {
										                            dOut = '<td class="center" ><span class="badge label-pill label-primary">跟踪中</span></td>';
										                        } 
										                        else if(data.outState=="3") {
										                            dOut = '<td class="center" ><span class="badge label-pill label-success">待回访</span></td>';
										                        } 
										                        else if(data.outState=="4") {
										                            dOut = '<td class="center" ><span class="badge label-pill label-success">完成</span></td>';
										                        } 
										                        return dOut;
										                    }
													},
													{
														data : "user.empLogin.userName",
													},

													{
														data : 'endTime',
														render : function(data,type, full,meta) {
															if (data) {
																return moment(data).format("YYYY-MM-DD");
															}
														}
													},
													{
														data : null,
														render : function(data,type, full,meta) {
															var dOut;
															if (data.isFinish == "1") {
																dOut = '<td class="center" >'+ moment(data.updateTime).format("YYYY-MM-DD")
																		+ '</td>';
															}
															return dOut;
														}

													}, {
														data : 'afterSummary'
													} ],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length
														+ oSettings._iDisplayStart;

												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$(
															'td:eq(0)',
															oSettings.aoData[oSettings.aiDisplay[k]].nTr)
															.text(i + 1);
													k++;
												}
												serverTable.off('click', 'tr');
												serverTable.on('click','tr',function(event) {
																	event = event|| window.event;
																	var target = event.target|| event.scrElement;
																	var data = serverTable.row(this).data();
//																	serverData1.ticketId = data.afterSaleTicket.id;
//																	serverData1.userId = data.user.id;
																	serverData1.outId = data.id;
																	serverTable1.draw();
																	return;
																});
											}
										});

					});
	var serverData1 = {};
	var serverTable1;
	jQuery(document).ready(function() {
						serverTable1 = jQuery('#ticketTranceTableNew').DataTable({
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/afterSaleOutHouse/getTrancePage',
												"data" : function(d) {
													return $.extend({}, d,
															serverData1);
												}
											},
											"iDisplayLength" : 5,
											columns : [
													{
														data : null,
														defaultContent : ""
													},
													{
														data : "activeType",
													},

													{
														data : 'createTime',
														render : function(data,type, full,meta) {
															if (data) {
																return moment(data).format("YYYY-MM-DD");
															}
														}
													}, {
														data : 'memo'
													} ],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length
														+ oSettings._iDisplayStart;

												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$(
															'td:eq(0)',
															oSettings.aoData[oSettings.aiDisplay[k]].nTr)
															.text(i + 1);
													k++;
												}

											}
										});

					});
	// 三包零件赔偿表datatable
	var serverData3 = {};
	serverData3.ticketId = $("#ticketId").val();
	var serverTable3;
	jQuery(document).ready(function() {
						serverTable3 = jQuery('#payDeviceTable').DataTable(
										{
											"serverSide" : true,
											"ordering" : false,
											"ajax" : {
												"dataType" : "json",
												"type" : "get",
												"cache" : false,
												"url" : window.rootPath
														+ '/ui/afterSaleInHouse/getPayDevicePage',
												"data" : function(d) {
													return $.extend({}, d,
															serverData3);
												}
											},
											"iDisplayLength" : 5,
											columns : [ {
												data : null
											},

											{
												data : 'partName'
											}, {
												data : 'figureNumber'
											}, {
												data : 'quantity'
											}, {
												data : 'material',

											}, {
												data : 'price',

											}, {
												data : 'sumPrice',

											}, {
												data : 'deviceMemo',

											} ],
											"drawCallback" : function(oSettings) {
												var k = 0;
												var total = oSettings.aiDisplay.length
														+ oSettings._iDisplayStart;

												for (var i = oSettings._iDisplayStart, iLen = total; i < iLen; i++) {
													$(
															'td:eq(0)',
															oSettings.aoData[oSettings.aiDisplay[k]].nTr)
															.text(i + 1);
													k++;
												}

											}
										});
					});
});